;(function($){
	
	var Carousel=function(poster){
		
		var self=this;
		this.poster=poster;
		
		this.setting={
			"width":1000,
			"height":300,
			"posterWidth":680,
			"posterHeight":300,
			"verticalValue":"middle",
			"scale":0.9,
			"speed":2000,
			"autoplay":true
		}
		
		this.setInitLocation();
		
		this.setItemShow();
		
	}
	
	Carousel.prototype={
		
		setItemShow:function(){
			
			var _this_=this,
				posterItems=this.poster.find(".poster_item").slice(1),
				layers=posterItems.length/2,
				leftSlice=posterItems.slice(0,layers),
				rightSlice=posterItems.slice(layers),
				gap=(this.setting.width-this.setting.posterWidth)/2/3,
				posterw=this.setting.posterWidth,
				lrWidth=(this.setting.width-this.setting.posterWidth)/2,
				scale=this.setting.scale,
				posterheight=this.setting.posterHeight,
				llevel=layers,
				rlevel=layers;
				
			
			//设置左边显示的帧数
			var lhscale=this.setting.posterHeight*this.setting.scale;
			
			leftSlice.each(function(i){
				var j=i;
				j++;
				llocation=(posterheight-lhscale)/2;
				
				$(this).css({
					"width":posterw,
					"height":lhscale,
					"position":"absolute",
					"top":llocation,
					"left":lrWidth-gap*j,
					"opacity":1/j,
					"z-index":llevel
				})
				llevel--;
				lhscale=lhscale*scale;
			})
			
			//设置右边显示的帧数
			var rhscale=this.setting.posterHeight*this.setting.scale;
			
			rightSlice.each(function(i){
				var j=i;
				j++;
				rlocation=(posterheight-rhscale)/2;
				
				$(this).css({
					"width":posterw,
					"height":rhscale,
					"position":"absolute",
					"top":rlocation,
					"left":lrWidth+gap*j,
					"opacity":1/j,
					"z-index":rlevel
				})
				llevel--;
				rhscale=rhscale*scale;
			})
			
		},
			
		setInitLocation:function(){
			var btnw=(this.setting.width-this.setting.posterWidth)/2-80;
			var itemleft=(this.setting.width/2-this.setting.posterWidth/2);
			var btntop=(this.setting.height-$(".btn img").height())/2;
			var btnimgwidth=(btnw-$(".btn img").width())/2;
			
			$(".poster_main").css({
				"height":this.setting.height,
				"width":this.setting.width
			})
			
			$(".poster_list").css({
				"height":this.setting.height,
				"width":this.setting.width
			})
			
			$(".poster_item").css({
				"width":this.setting.posterWidth,
				"height":this.setting.posterHeight,
				"position":"absolute",
				"top":"0px",
				"left":itemleft
			})
			
			$(".btn").css({
				"width":btnw,
				"z-index":10
			})
			
			$(".btn img").css({
				"position":"absolute",
				"top":btntop,
				"left":btnimgwidth
			})
			
			$(".btn").css({
				"width":btnw,
				"display":"inline-block",
				"text-align":"center",
				"z-index":10
			})
			
			$(".prebtn").mouseover(function(){
				$(".prebtn").css({
					"background-color":"gray",
					"opacity":0.5
				})
			})
			
			$(".prebtn").mouseleave(function(){
				$(".prebtn").css({
					"background-color":"white",
					"opacity":0
				})
			})
			
			$(".nextbtn").mouseover(function(){
				$(".nextbtn").css({
					"background-color":"gray",
					"opacity":0.5
				})
			})
			
			$(".nextbtn").mouseleave(function(){
				$(".nextbtn").css({
					"background-color":"white",
					"opacity":0
				})
			})
			
			var firstItem=this.poster.find(".poster_item").eq(0);
			console.log(firstItem);
			firstItem.css({
				"width":this.setting.posterWidth,
				"height":this.setting.posterHeight,
				"z-index":9
			})
		}
	}
	
	Carousel.init=function(posters){
		var _this_=this;
		posters.each(function(){
			new _this_($(this));
		});
	}
	
	window["Carousel"]=Carousel;
	
})($);
